$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加折扣券领取记录', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field: 'z_num',
                title: '折扣数值',
                unresize: true,
                align: 'center'
            },{
                field: 'use_validate',
                title: '使用条件',
                unresize: true,
                align: 'center'
            },{
                title: '使用时间',
                unresize: true,
                align: 'center',
                 templet:function(d){
                    return d.start_use+' 至 '+ d.end_use;
                },
            }, {
                field: 'get_user_id',
                title: '领取人ID',
                unresize: true,
                align: 'center'
            }, {
                field: 'coupon_code',
                title: '核销编码',
                unresize: true,
                align: 'center'
            }, {
                field: 'status',
                title: '状态 ',
                unresize: true,
                align: 'center',
                templet:function(d){
                    if(d.status == 0){
                        return '<span style="color:#6590DC">未使用</span>';
                    }else if(d.status == 2){
                        return '<span style="color:#E7DB74">已过期</span>';
                    }else{
                        return '<span style="color:#444">已使用</span>';
                    }
                },
            }, {
                field: 'add_time',
                title: '领取时间',
                unresize: true,
                align: 'center'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('编辑折扣券领取记录', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该折扣券领取记录吗?', 'before_coupon_get', obj.data.id);
        }
    });
});
